using System.Collections.Generic;
using System.Drawing;

namespace ICSharpCode.TextEditor
{
    public class ThemesMapManager
    {
        private static object syncRoot = new object();

        private static IThemeColorMatcher matcher = null;

        private static Dictionary<string, Dictionary<string, Color>> themesMap = null;

        internal static string selectedTheme { get; set; }

        internal static Dictionary<string, Dictionary<string, Color>> ThemesMap => themesMap;

        internal static Color getThemeMapColor(string theme, string name)
        {
            Color value = matcher.Color;
            Dictionary<string, Color> dictionary = ThemesMap[theme];
            if (dictionary.TryGetValue(name, out value))
            {
                return value;
            }
            return Color.White;
        }

        internal static void GenerateThemeMap(string theme)
        {
            lock (syncRoot)
            {
                selectedTheme = theme;
                if (!(theme == "Default"))
                {
                    themesMap = new Dictionary<string, Dictionary<string, Color>>();
                    Dictionary<string, Color> dictionary = new Dictionary<string, Color>();
                    if (theme == "Black")
                    {
                        matcher = new BlackThemeMatcher(dictionary);
                    }
                    themesMap.Add(theme, dictionary);
                }
            }
        }

        internal static Color MatchThemeColor(Color color, string name)
        {
            return matcher.Resolve(color, name);
        }
    }
}
